package com.qf.controller;

import com.qf.entity.Emp;
import com.qf.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.sql.SQLException;

@RequestMapping("/user")
@Controller
public class UserController {
    @Autowired
    private EmpService empService;

    @RequestMapping("/login")
    public String login(String username, String password, HttpSession session) throws SQLException {
        Emp emp = empService.select(username, password);
//        System.out.println(emp);
        if (emp != null && emp.getEname().equals(username) && emp.getPwd().equals(password)) {
            session.setAttribute("loginUser", username);
            return "index";
        }
        return "commons/login";
    }
}
